package com.atguigu.tingshu.order.configs;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Configuration
public class CancelOrderConfig {

    @Bean
    public CustomExchange cancelExchange(){
        //设置参数
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-typel","direct");
        //返回
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue cancelQueue(){
        return new Queue(MqConst.QUEUE_CANCEL_ORDER,true,false,false);
    }

    @Bean
    public Binding cancelBinding(){
        return BindingBuilder.bind(cancelQueue()).to(cancelExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
